// 常见方法
console.log("hello world".length);
console.log("hello world".charAt(1));
console.log("hello world".replace("hello", "hi"));
console.log("hello world".toUpperCase());
console.log("hello world".toLocaleUpperCase());

// 逻辑语
console.log(1 > 2 && 1 < 1);
console.log(1 > 0 || 1 < 0);
console.log(!1 == 1);

//变量
var myname = "廖风顺";
myname = "风顺";
console.log(myname);

const a_pi = Math.PI;
console.log(a_pi);

//运算符
var x = 5;
x += 5;
console.log(x);

var y = 5;
y = y + "字符串";
console.log(y);
// 两个等号会自动转换类型，三个不会自动转换
console.log("123" == 123);
console.log("123" === 123);


//控制语句,var没有作用域,let会让变量被锁在对应代码块
var s_name = "simon";
var s_age = 11;
if (s_name == "simon"&&s_age>10) {
    console.log("simon");
} else if(s_sex=='female'){
    console.log("not simon");
}

var count = 1;
while (count < 5) {
    console.log("hello world");
    count += 1;
}

do {
    console.log("do while")
    count += 1;
} while (count == 5)

for (var v = 0; v < 10; v++){
    console.log("the " + (v+1) + " time to print log");
}

// 三元运算符
var age = 19;
var allow = age == 19 ? "通过" : "未通过";
console.log(allow)

switch (age) {
    case 19:
        console.log("已满19");
        break;
    case 20:
        console.log("已满20");
        break;
    default:
        console.log("默认");
        break;
}

//对象
var obj1 = new Object();
obj2={}
obj1 = {
    "name": "廖风顺",
    "age": 23,
    "sex": "male",
    "contect": {
        "email": "1508034450@qq.com",
        "qq":"1508034450"
    }
}
console.log(obj1.contect.qq);
console.log(obj1["contect"]["qq"]);

obj1.name = "lfs";
console.log(obj1.name);
obj1.school = "cjlu";
console.log(obj1.school);

//数组
var a = new Array();
a[0] = "hello";
a[1] = "world";
console.log(a.length);
a[5] = "five";
console.log(a);

var animal = ["dog", "pig", "fish", "cat"];
console.log(animal);
for (let i = 0; i < animal.length; i++){
    console.log(animal[i]);
}
//for in在遍历数组时不会遍历出空的元素
for (let i in animal.length){
    console.log(animal[i]);
}

//函数
let a_number = 1;
function add(x) {
    a_number+=x;
}
add(10);
console.log(a_number);

//递归函数
function re(x) {
    x += 1;
    if (x < 100) {
        re(x);
    } else {
        console.log(x);
    }
}
re(10);

//函数闭包 外层函数传入一个参数但是内层的函数也需要传一个参数
let num1 = 10;
function doadd(num1) {
    return function (num2) {
        return num1 + num2;
    }
}
//传入第一个参数，返回的是一个函数
var inner = doadd(num1);
//调用返回的这个函数，得到结果值
var result = inner(5);
console.log(result);